﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FindPackage.DTO;
using MySql.Data.MySqlClient;

namespace FindPackage.DAL
{
    public class Encomenda_DAL
    {
        #region Variaveis
        private List<Encomenda_DTO> lstEncomenda_DTO;
        private MySqlDataReader oMySqlDataReader;
        private MySqlParameter[] paramMysqlArray;
        private Retorno_DTO oRetorno_DTO = null;
        #endregion
        public List<Encomenda_DTO> getListaEncomenda()
        {
            try
            {

                paramMysqlArray = new MySqlParameter[2];
                paramMysqlArray[0] = new MySqlParameter("COD_RETORNO", MySqlDbType.Int32);
                paramMysqlArray[0].Direction = System.Data.ParameterDirection.Output;

                paramMysqlArray[1] = new MySqlParameter("DSC_RETORNO", MySqlDbType.VarChar, 500);
                paramMysqlArray[1].Direction = System.Data.ParameterDirection.Output;

                IDBConnection conn = new DBConnection();
                oRetorno_DTO = conn.ExecutarReader("prc_encomenda_get", paramMysqlArray,
                                     System.Data.CommandType.StoredProcedure);

                if (oRetorno_DTO.pCOD_RETORNO == 0)
                {
                    if (oMySqlDataReader.HasRows != false)
                    {

                        lstEncomenda_DTO = new List<Encomenda_DTO>();
                        while (oMySqlDataReader.Read())
                        {
                            lstEncomenda_DTO.Add(new Encomenda_DTO()
                            {
                                pCodEncomenda = Convert.ToInt32(oMySqlDataReader["COD_ENCOMENDA"]),
                                pCodUsuario = Convert.ToInt32(oMySqlDataReader["COD_USUARIO"]),
                                pNumEncomenda = Convert.ToString(oMySqlDataReader["NUM_ENCOMENDA"]),
                                pCodTipoEncomenda = Convert.ToInt32(oMySqlDataReader["COD_TIPO_ENCOMENDA"]),
                                pDatInclusao = Convert.ToDateTime(oMySqlDataReader["DAT_INCLUSAO"]),
                                pDatAtualizacao = Convert.ToDateTime(oMySqlDataReader["DAT_ATUALIZACAO"]),
                                IndStatus = Convert.ToString(oMySqlDataReader["IND_STATUS"])
                            });
                        }
                    }
                }
                return lstEncomenda_DTO;

            }
            catch (Exception ex)
            {

                throw;
            }
        }
    }
}
